From 819af01db1ecb76ca09c7fa17758ff5e920011aa Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 22 Jul 2015 14:33:52 -0700 Subject: [PATCH] etc: Use Popen instead of call to spawn processes I saw the usage of `call` locking up quite a bit when running this script on Windows, and googling around on the internet seems to indicate that Popen should be used instead of call to prevent this locking up, and it does indeed work! --- src/etc/download.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/etc/download.py b/src/etc/download.py index 2a6636ccf..080fda9e2 100644 --- a/src/etc/download.py +++ b/src/etc/download.py @@ -31,8 +31,19 @@ def unpack(tarball, dst, quiet=False): shutil.move(tp, fp) shutil.rmtree(os.path.join(dst, fname)) -def run(args): - print("running: " + ' '.join(args)) - ret = subprocess.call(args) - if ret != 0: - raise Exception("failed to fetch url: " + url) +def run(args, quiet=False): + if not quiet: + print("running: " + ' '.join(args)) + sys.stdout.flush() + # Use Popen here instead of call() as it apparently allows powershell on + # Windows to not lock up waiting for input presumably. + ret = subprocess.Popen(args, + stdin = subprocess.PIPE, + stdout = subprocess.PIPE, + stderr = subprocess.PIPE) + out, err = ret.communicate() + code = ret.wait() + if code != 0: + print("stdout: \n\n" + out) + print("stderr: \n\n" + err) + raise Exception("failed to fetch url") -- 2.30.2